const BASE_URL = 'https://www.dexte.pro/gate-api/gate';
// const BASE_URL = "http://97.64.82.110:8010/gate";

const headers = {
  "Content-Type": "application/json",
};

export async function get(url, body = {}) {
  const queryString = new URLSearchParams(body).toString();
  const fullUrl = `${BASE_URL}${url}${queryString ? `?${queryString}` : ""}`;
  console.log(fullUrl, "fullUrl");

  try {
    const response = await fetch(fullUrl, {
      method: "GET",
      headers,
    });
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return await response.json();
  } catch (error) {
    console.error(`GET Error:`, error);
    throw error;
  }
}

export async function post(url, body = {}) {
  const fullUrl = `${BASE_URL}${url}`;
  // const fullUrl = `${url}`;

  try {
    const response = await fetch(fullUrl, {
      method: "POST",
      headers,
      body: JSON.stringify(body),
    });
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return await response.json();
  } catch (error) {
    console.error(`POST Error:`, error);
    throw error;
  }
}
